const { OpenAI } = require("openai");

const openai = new OpenAI({
    // apiKey: process.env['OPENAI_API_KEY'],
});

async function main() {
  const stream = await openai.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: 'Tell me something that is funny.' }],
    stream: true,
  });
  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
  process.stdout.write("\n");
}

main();